package com.song.ssm.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @Author 宋伟宁
 * @Date 2023/9/1
 * @Version 1.0
 **/
@PropertySource("classpath:db.properties")
public class JdbcConfig {

    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.driverClassName}")
    private String driver;

    @Value("${jdbc.username}")
    private String username;

    @Value("${jdbc.password}")
    private String password;

    @Value("${maxActive}")
    private Integer maxActive;

    @Value("${maxWait}")
    private long maxWait;

    @Value("${initialSize}")
    private Integer initSize;
    @Bean
    public DataSource dataSource(){
        DruidDataSource ds = new DruidDataSource();
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        ds.setMaxActive(this.maxActive);
        ds.setInitialSize(this.initSize);
        ds.setMaxWait(this.maxWait);
        return ds;
    }
}
